﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="AddLinkMan.aspx.cs" Inherits="ZX.WebApp.Crm.Customer.AddLinkMan" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/yahoo-dom-event/yahoo-dom-event.js"></script>
    <script type="text/javascript" src="../../Scripts/yui_2.9.0/build/connection/connection-min.js"></script>
    <script src="../../Scripts/jquery-1.6.min.js" type="text/javascript"></script>
    <script src="../../Scripts/jquery.json-2.2.min.js" type="text/javascript"></script>
    <script src="../../Scripts/Jquery.form.js" type="text/javascript"></script>
    <script src="../../Scripts/extend.validate.js" type="text/javascript"></script>
    <link href="../../Styles/base.css" rel="stylesheet" type="text/css" />
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <table id="fieldTable">
            <tr>
                <td width="100">联系人姓名：<span style="color: Red">*</span></td>
                <td>
                    <input type="text" id="Caption" name="Caption" maxlength="30" onblur="IsChinese(this.value,'联系人姓名','Caption')"
                           style="width:150px;" />
                </td>
            </tr>
            <tr>
                <td>手机号：<span style="color: Red">*</span></td>
                <td>
                    <input type="text" id="MobileTel" name="MobileTel" runat="server" onkeyup="this.value=this.value.replace(/\D/g,'')"
                           onafterpaste="this.value=this.value.replace(/\D/g,'')" style="width:150px;" />
                </td>
            </tr>
            <tr>
                <td>联系人类型：<span style="color: Red">*</span></td>
                <td> 
                    <asp:DropDownList ID="TypeID" runat="server" AppendDataBoundItems="true" Width="160">
                        <asp:ListItem Value=""> </asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>与决策人关系：<span style="color: Red">*</span></td>
                <td> 
                    <asp:DropDownList ID="Relation" runat="server" AppendDataBoundItems="true" Width="160">
                        <asp:ListItem Value=""> </asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>性别：<span style="color: Red">*</span></td>
                <td> 
                    <asp:DropDownList ID="Sex" runat="server" AppendDataBoundItems="true" Width="160">
                        <asp:ListItem Value=""> </asp:ListItem>
                        <asp:ListItem Value="M">男</asp:ListItem>
                        <asp:ListItem Value="F">女</asp:ListItem>
                    </asp:DropDownList>
                </td>
            </tr>
            <tr>
                <td>职位：<span style="color: Red">*</span></td>
                <td>
                    <input type="text" id="Position" name="Position" onblur="IsChinese(this.value,'职位','Position')"
                           style="width:150px;" />
                </td>
            </tr>
            <tr>
                <td>所属部门：</td>
                <td>
                    <input type="text" id="DeptName" name="DeptName" maxlength="20"
                           style="width:150px;" />
                </td>
            </tr>
            <tr>
                <td>联系人邮箱：</td>
                <td>
                    <input type="text" id="Email" name="Email" onblur="isEmail(this.value,'联系人邮箱','Email')"
                           style="width:150px;" />
                </td>
            </tr>
        </table>
        <input type="hidden" id="Code" name="Code" runat="server" />
    </div>
    </form>
</body>
<script type="text/javascript">
    var CustomerId = "<%=CustomerID %>";
    var instance = [{ "Code": "", "Caption": "", "MobileTel": "", "TypeID": "", "Sex": "",
        "Position": "", "DeptName": "", "Email": "", "Relation": ""
    }];
    function Save() {
        instance[0].Code = $("#Code").val();
        $("#fieldTable").SetFormValueToObject(instance[0]);
        if (instance[0].Code == "") {
            alert("客户编码不能为空!");
            parent._DialogState = "0";
            return;
        }
        if (instance[0].Caption == "") {
            alert("联系人姓名不能为空!");
            $("#Caption").focus();
            parent._DialogState = "0";
            return;
        }
        if (instance[0].MobileTel == "") {
            alert("手机号不能为空!");
            $("#MobileTel").focus();
            parent._DialogState = "0";
            return;
        }
        if (instance[0].MobileTel.length != 11) {
            alert("请输入11位的手机号!")
            $("#MobileTel").focus();
            parent._DialogState = "0";
            return;
        }
        if (instance[0].TypeID == "") {
            alert("联系人类型不能为空!");
            $("#TypeID").focus();
            parent._DialogState = "0";
            return;
        }
        if (instance[0].Relation == "") {
            alert("与决策人关系不能为空!");
            $("#Relation").focus();
            parent._DialogState = "0";
            return;
        }
        if (instance[0].Sex == "") {
            alert("性别不能为空!");
            $("#Sex").focus();
            parent._DialogState = "0";
            return;
        }
        if (instance[0].Position == "") {
            alert("职位不能为空!");
            $("#Position").focus();
            parent._DialogState = "0";
            return;
        }
        if (CustomerId != "") {
            parent._DialogState = "";
            instance[0].CustomId = CustomerId;
            var json = $.toJSON(instance[0]).replace(/'/g, "[B]");
            SaveData(json);
        } else {
            alert("客户ID为空,保存失败！");
            parent._DialogState = "0";
            return;
        }
    }
    function SaveData(obj) {
        YAHOO.util.Connect.asyncRequest('POST', '../../Extend/AjaxData/CustomOperating.aspx?action=insert&entity=CrmLinkMan&json=' + encodeURI(obj), {
            success: function (res) {
                var inventory;
                try {
                    inventory = res.responseText;
                    if (inventory == "1") {
                        alert("保存成功!");
                        location.reload(false);
                        parent.LoadLinkMan();
                    } else {
                        alert("保存失败!");
                    }
                }
                catch (e) {
                }
                finally {
                }
            },
            failure: function (error) {
                alert("数据错误：" + error.statusText);
            }
        }, null);
    }
</script>
</html>
